package com.tender.properties;

import com.tender.utils.cryptography.RSAUtil;
import com.tender.utils.cryptography.AESUtil ;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Base64;

/**
 * @see RSAUtil
 *
 */
@Data
@ConfigurationProperties(prefix = "com.secret.config")
public class SecretConfigProperties {

    /**
     * 公钥字符串
     */
    private String publicKeyStr = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlfA4Ed+iPmX3UeVcG1Uqjgl5wsASN669NSyO0Jrf0FauC8rjM4jQlqSZFROTb2tlMLFiVNJPTCOhrqGTf1TzubsoU8lprm000G8Xg4YPRO3zmMaDgyKmWcjWydoE4uBRlf7K4+12Dlw/gTaCZDdVNpdyaTSZ1tu2dyCGWOICpbXlIA9hdkam6JDU0hsjaHoMcLC61w+IzQTIJlUHh5BJE/jao9Qr8AV9gYW0+3BtT9Pu38kc/mA5rjxapAxnhfOKSfy9V0ipBsvdNuA6zDgdo2slLj/EwQogtG48U2Q/4pIN89/61DKdqCfHfAi6DBQBwAOnNcyRaA/IXH7BVHc0FwIDAQAB";

    /**
     * 私钥字符串
     */
    private String privateKeyStr = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCV8DgR36I+ZfdR5VwbVSqOCXnCwBI3rr01LI7Qmt/QVq4LyuMziNCWpJkVE5Nva2UwsWJU0k9MI6GuoZN/VPO5uyhTyWmubTTQbxeDhg9E7fOYxoODIqZZyNbJ2gTi4FGV/srj7XYOXD+BNoJkN1U2l3JpNJnW27Z3IIZY4gKlteUgD2F2RqbokNTSGyNoegxwsLrXD4jNBMgmVQeHkEkT+Nqj1CvwBX2BhbT7cG1P0+7fyRz+YDmuPFqkDGeF84pJ/L1XSKkGy9024DrMOB2jayUuP8TBCiC0bjxTZD/ikg3z3/rUMp2oJ8d8CLoMFAHAA6c1zJFoD8hcfsFUdzQXAgMBAAECggEAWItJsVRtjYfNq/FUmVeMD+EMpLOkjnmEhthP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qwiLjsr8rpz7r6i0RX1602fFYS3JtNdkd0QMSRc6YAL05lQZPjbvcSmuUZjaZt3zOMXTo/mayggbHgIlV/xlVjHw==";

    /**
     * AES secret (被 RAS 公钥加密后如下：)
     */
    private String secretAES128 = "a7hSw4kwlwqPlLOrvexd5w9kaq0OolYyjf+vsi3GLtn3U48y/7jjrR1PFbplGP4/4SN7lCH1JlmVkBJFo/VZEK0DF5o1joGymlYq0V0KxitetlTdrWlsJ48toQjkcFE4EG05U6wrRjStJcjqd5DeM5CuKQiawqHuenzSnrZAmLC4+PEDSp6CtCfp6PQnYW4+TqObOb+yhSxQHO5h+xI9QzzwKd/CtSP+m8HlDNVryBFSC/xVMgBbrFzXiOlwsVCdjA+a7tUk3HwT6uFrx+ApuGhdbs+NKjG/FfCs4KEk1AG+/DWt2REBmyqf/ZJnTBxSosb+LXh6jfSAb4JdcjuWKQ==";

    /**
     * AES 密钥原始内容
     */
    private String keyAES128 = "o2OswWMuB1Xp+39YGlFltA==";

    /**
     * iv 偏移量 （被 base64 编码过）
     */
    private String ivAES = "Cezx1RgL2Q96ThoIp3cnog==";

    public static void main(String[] args) {
        System.out.println("============== 单独测试 ==============");
        System.out.println();
        String userInfo = "{\"idNo\":\"320981199109085715\",\"phoneNo\":\"13259716664\",\"username\":\"bruce\"}";
        SecretConfigProperties configProperties = new SecretConfigProperties();
        String encrypt = AESUtil.encrypt(configProperties.getKeyAES128(), userInfo, Base64.getDecoder().decode(configProperties.getIvAES()));
        // EpWzO0UcrxMbT6TQhNxsv7ON6IHVAB/HbLI7slAc7P8rmPpVuduI9g/LZVqmy6Qfry8fbrI9kyJJ5CK4wo7GGGguXKob7d943lAhICwq/Bc=
        // 手机号码为空：EpWzO0UcrxMbT6TQhNxsv/Fm67Y/vhIi4O8NFkz7d9NUBt5eHsG0txBCcCgLy5ynZXy4585x0Is7rs8oV6f1Zw==
        // 手机号码格式错误：EpWzO0UcrxMbT6TQhNxsv/Fm67Y/vhIi4O8NFkz7d9Mt8SwUjlNhvxWMDYDxjmBmYCGBf9R0Vce7VqUQL9j/Npss1nkR9acQ2NgChVzn06M=
        // 身份证号码格式错误：EpWzO0UcrxMbT6TQhNxsv+B+LrX51DBH9M+Wm5bOp/0+AlxsTDe+5dMdI0QUgUo4wO23NeDp8Hnt8MbPTDdVUFar+iqq1vvqwHzy6kTjwD0=
        System.out.println("============== 用户信息加密后 ============== " + encrypt);
        System.out.println();
        String decrypt = AESUtil.decrypt(configProperties.getKeyAES128(), encrypt, Base64.getDecoder().decode(configProperties.getIvAES()));
        System.out.println("============== 用户信息解密后 ============== " + decrypt);
    }

    /*
 *****************************************
 ************** 测试前后端全流程 **************
 *****************************************

=========== 模仿前端请求内容 ============ this is my handsome friend

=========== RSA -> 公钥（publicKey）为：MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlfA4Ed+iPmX3UeVcG1Uqjgl5wsASN669NSyO0Jrf0FauC8rjM4jQlqSZFROTb2tlMLFiVNJPTCOhrqGTf1TzubsoU8lprm000G8Xg4YPRO3zmMaDgyKmWcjWydoE4uBRlf7K4+12Dlw/gTaCZDdVNpdyaTSZ1tu2dyCGWOICpbXlIA9hdkam6JDU0hsjaHoMcLC61w+IzQTIJlUHh5BJE/jao9Qr8AV9gYW0+3BtT9Pu38kc/mA5rjxapAxnhfOKSfy9V0ipBsvdNuA6zDgdo2slLj/EwQogtG48U2Q/4pIN89/61DKdqCfHfAi6DBQBwAOnNcyRaA/IXH7BVHc0FwIDAQAB

=========== RSA -> 私钥（privateKey）为：MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCV8DgR36I+ZfdR5VwbVSqOCXnCwBI3rr01LI7Qmt/QVq4LyuMziNCWpJkVE5Nva2UwsWJU0k9MI6GuoZN/VPO5uyhTyWmubTTQbxeDhg9E7fOYxoODIqZZyNbJ2gTi4FGV/srj7XYOXD+BNoJkN1U2l3JpNJnW27Z3IIZY4gKlteUgD2F2RqbokNTSGy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OqJ3SRFRmuDq4Vhh3/FvBtChSir6IrOBr/1mrbetSh5Q5JIchbYwy0J8yc2PyCs72RjKJykvYWpO9cNnn09+CsD50iaT/100Y30kDVjhMHC0a0c+aDOM0CgYBmI0cp3ecCGSl6VSrOL8yJ1KYwQXKYkaQ7qxA5VFHS7q/OZzYswNAYr6bcwvUK4igK38q3ISy+iG/LfV6U5xqwiLjsr8rpz7r6i0RX1602fFYS3JtNdkd0QMSRc6YAL05lQZPjbvcSmuUZjaZt3zOMXTo/mayggbHgIlV/xlVjHw==

=========== AES -> iv 字节数组 ============ [B@ed1f14

=========== AES -> iv base64 '编码'后 ivAES ============ Cezx1RgL2Q96ThoIp3cnog==

=========== AES -> iv base64 '解码'后 ============ [B@29724f

=========== AES -> keyAES128 加密秘钥明文 ========== o2OswWMuB1Xp+39YGlFltA==

=========== AES -> RSA 公钥加密后的 secretAES128 密文 ========== a7hSw4kwlwqPlLOrvexd5w9kaq0OolYyjf+vsi3GLtn3U48y/7jjrR1PFbplGP4/4SN7lCH1JlmVkBJFo/VZEK0DF5o1joGymlYq0V0KxitetlTdrWlsJ48toQjkcFE4EG05U6wrRjStJcjqd5DeM5CuKQiawqHuenzSnrZAmLC4+PEDSp6CtCfp6PQnYW4+TqObOb+yhSxQHO5h+xI9QzzwKd/CtSP+m8HlDNVryBFSC/xVMgBbrFzXiOlwsVCdjA+a7tUk3HwT6uFrx+ApuGhdbs+NKjG/FfCs4KEk1AG+/DWt2REBmyqf/ZJnTBxSosb+LXh6jfSAb4JdcjuWKQ==

=========== data -> 请求内容被 AES 加密后  ========== 8jdGyakvP21XwfqdmRFkLh4+D10YVAUr2QfvtWW94FM=

 =========== 后端解密后的 AES 密钥 ========== o2OswWMuB1Xp+39YGlFltA==

 =========== 后端解密后的 请求内容 ========== this is my handsome friend
*/
}
